<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>服务地址</title>
	<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0, maximum-scale=1.0">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link type="text/css" rel="stylesheet" media="screen" href="__FONT__/css/style.css"/>
    <link type="text/css" rel="stylesheet" media="screen" href="__FONT__/css/media.css"/>
    <script type="text/javascript" src="__FONT__/js/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="__FONT__/js/jquery.autocomplete.js"></script>
    <style>
		.autocomplete-suggestions{width: 100%; background: white;}
		.autocomplete-suggestion{ line-height: 40px; border-bottom: 1px solid #ccc;}
	</style>
</head>
<body style="background:#f7f7f9;">
	<include file="Public/customHeader" title="服务地址" url="javascript: history.go(-1);"/>
 	<section class="beauty_sec search">
      	<div class="searchdiv">
      		<input type="hidden" name="latitude" id="latitude">
      		<input type="hidden" name="longitude" id="longitude">
        	<input type="text" id="sourceAutocomplete" placeholder="请输入小区名或大厦名">
        	<input type="button" id="startSearch" class="label">
      	</div>
      	<span>请填写服务地址为您<strong>就近匹配</strong></span>
      	<div class="searchResultContainr hasResult">
        	<ul></ul>
		</div>
	</section>
	<script>
	$(function () {
		function ArrayToURL(array) {
			var pairs = [];
			for (var key in array)
			if (array.hasOwnProperty(key))
				pairs.push(encodeURIComponent(key) + '=' + encodeURIComponent(array[key]));
			
			return pairs.join('&');
		}
		
		$('.searchResultContainr').css('top', $('#sourceAutocomplete').outerHeight(true)+'px');
		
		function getLocation() {
			var location = localStorage.getItem('location');
			return location;
		}
		
		function getProvince() {
			return localStorage.getItem('select_province');
		}
		
		function getCity() {
			return localStorage.getItem('select_city');
		}
		
		$('#sourceAutocomplete').autocomplete({
			serviceUrl: '{:U("/Index/searchAddress")}',
			minChars: 2,
			params: {
				province: getProvince(),
				city: getCity(),
			},
			width: '100%',
			maxHeight: '100%',
			showNoSuggestionNotice: true,
			noSuggestionNotice: 'Sorry, no matching results',
			triggerSelectOnValidInput: false,
			onSelect: function (suggestion) {
				var redirect = '{$redirect}';
				
				var params = {
					longitude: suggestion.location.lng,
					latitude: suggestion.location.lat,
					address: $('#sourceAutocomplete').val(),
				};
				
				window.location.href = redirect+'?'+ArrayToURL(params);
			}
		});
	});
	</script>
</body>
</html>